package org.example.error;


import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常发生，会走此类写的handler！
@ControllerAdvice  //可以返回逻辑视图 转发和重定向
@RestControllerAdvice  //只能返回json数据
public class GlobalExceptionHandler {

    @ExceptionHandler(ArithmeticException.class)
    public Object ArithemeticExceptionHandler(ArithmeticException e) {
        return "ArithmeticException";
    }

    @ExceptionHandler(NullPointerException.class)
    public Object NullPointerExceptionHandler(NullPointerException e) {
        return "NullPointerException";
    }
}
